﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Controls;
using System.Windows;

namespace Anagramme.Controls
{
    /// <summary>
    /// <see cref="ContentControl"/> qui notifie le changement de contenu
    /// </summary>
    public class AnimatedContentControl : ContentControl
    {
        #region Routed Events
        /// <summary>
        /// Se produit lors du changement du contenu de l'objet
        /// </summary>
        public static readonly RoutedEvent ContentChangedEvent =
            EventManager.RegisterRoutedEvent("ContentChanged", RoutingStrategy.Bubble, typeof(RoutedEventHandler), typeof(AnimatedContentControl));
        #endregion

        #region Constructors
        /// <summary>
        /// Crée une nouvelle instance de la classe <see cref="AnimatedContentControl"/>
        /// </summary>
        public AnimatedContentControl()
        {
            this.DefaultStyleKey = typeof(AnimatedContentControl);
        }
        #endregion

        #region Events
        /// <summary>
        /// Se produit lors du changement du contenu de l'objet
        /// </summary>
        public event RoutedEventHandler ContentChanged
        {
            add { AddHandler(ContentChangedEvent, value); }
            remove { RemoveHandler(ContentChangedEvent, value); }
        }
        #endregion

        #region Methods
        private void RaiseContentChangedEvent()
        {
            RoutedEventArgs args = new RoutedEventArgs(AnimatedContentControl.ContentChangedEvent);
            RaiseEvent(args);
        }
        #endregion

        #region ContentControl Overrides
        /// <summary>
        /// Appelle l'évènement ContentChangedEvent
        /// </summary>
        /// <param name="oldContent">Ancien contenu</param>
        /// <param name="newContent">Nouveau contenu</param>
        protected override void OnContentChanged(object oldContent, object newContent)
        {
            base.OnContentChanged(oldContent, newContent);
            RaiseContentChangedEvent();
        }
        #endregion
    }
}
